package com.zjkj.mp.controller.messageManage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zjkj.mp.service.message.SendInfoService;
import com.zjkj.mp.utils.Global;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.utils.Toolkit;
import com.zjkj.mp.vo.message.Message;

/**
 * 
 * 发送报告控制器
 *
 * @author 陈晨
 * @history
 * <TABLE id="HistoryTable" border="1">
 * 	<TR><TD>时间</TD><TD>描述</TD><TD>作者</TD></TR>
 *	<TR><TD>2013-6-9</TD><TD>创建初始版本</TD><TD>陈晨</TD></TR>
 * </TABLE>
 */
@Controller
public class SendInfoController {

	@Resource(name = "sendInfoServiceImpl")
	private SendInfoService sendInfoService;
	@Resource
	private Toolkit tool;

	/******************************* 发送报告 ***********************************/

	/** 
	 * 发送信息分页列表
	 * @return
	 */
	@RequestMapping("/showSendInfoList.do")
	public String showSendInfoList(HttpServletRequest req) {
		String pageNoStr = req.getParameter("pageNo");
		String fsId = req.getParameter("fsId");
		String realName = req.getParameter("realName");
		String sendDate = req.getParameter("sendDate");
		String endDate = req.getParameter("endDate");
		int pageNo = 1;
		PaginatedResult result;
		if(pageNoStr != null){
			pageNo = Integer.parseInt(pageNoStr);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if(!"".equals(realName) && null != realName)
			map.put("realName", realName);
		if(!"".equals(endDate) && null != endDate){
			endDate = tool.getTrimDate(endDate);
			map.put("endDate", endDate +"235959");
		}
		if(!"".equals(sendDate) && null != sendDate){
			sendDate = tool.getTrimDate(sendDate);
			map.put("sendDate", sendDate +"000000");
		}
		if(fsId != null){
			map.put("tdId", fsId);
		}
		result = this.sendInfoService.getMessagePageList(pageNo, Global.PAGESIZE, map);
		req.setAttribute("result", result);		
		req.setAttribute("realName", realName);
		if(!"".equals(endDate) && null != endDate){
			req.setAttribute("sendDate", tool.getSplitDate(sendDate));
		}else{
			req.setAttribute("sendDate", sendDate);
		}
		if(!"".equals(sendDate) && null != sendDate){
			req.setAttribute("endDate", tool.getSplitDate(endDate));
		}else{
			req.setAttribute("endDate", endDate);
		}
		return "message/sendInfo";
	}
	
	/** 
	 * 发送信息明细分页列表
	 * @return
	 */
	@RequestMapping("/showSendInfoMxList.do")
	public String showSendInfoMxList(HttpServletRequest req) {
		String pageNoStr = req.getParameter("pageNo");
		String fsId = req.getParameter("fsId");
		int pageNo = 1;
		PaginatedResult result;
		if(pageNoStr != null){
			pageNo = Integer.parseInt(pageNoStr);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if(fsId != null){
			map.put("fsId", fsId);
		}
		result = this.sendInfoService.getMessageMxPageList(pageNo, Global.PAGESIZE, map);
		req.setAttribute("result", result);		
		req.setAttribute("fsId", fsId);
		return "message/sendInfoMx";
	}
	
	/**
	 * 根据标识查询通道列表
	 * @return
	 */
	@RequestMapping("/showSendInfoListById.do")
	public String showAllListById(HttpServletRequest req) {
		String tdId = req.getParameter("tdId");
		List<Message> list = sendInfoService.getMessageList(Integer.parseInt(tdId));
		req.setAttribute("channelList", list);
		return "message/sendInfo";
	}
	
	/**
	 * 根据标识删除发送及明细信息
	 * @return
	 */
	@RequestMapping("/delMessage.do")
	public String delChannelById(HttpServletRequest req) {
		String tdId = req.getParameter("tdId");
		int num = sendInfoService.delMessage(tdId);
		if(num>0){
			req.setAttribute("info", "删除成功");
		} else {
			req.setAttribute("info", "删除失败");
		}
		return "message/sendInfo";
	}
	
	/**
	 * 根据标识编辑通道信息
	 * @return
	 */
//	@RequestMapping("/viewMessage.do")
//	public String viewMessageById(HttpServletRequest req) {
//		String tdId = req.getParameter("tdId");
//		List<Message> list = sendInfoService.getMessageList(Integer.parseInt(tdId));
//		Message mc = list.get(0);
//		req.setAttribute("message", mc);
//		return "message/viewMessage";
//	}
	
}
